#include "libAcoustX/solver/bhp/BHPShdParser.h"
#include "libAcoustX/solver/bhp/BHPCaller.h"
#include "libAcoustX/solver/bhp/BHPSolver.h"

#include "reader/NCoreReader.h"
#include "helper/NCorePathHelper.h"
#include "unidata/NCoreEnvirDate.h"

int main() 
{
	ncore::reader::Area area(-30, 30, -30, 30, 0.0, 20000);
	auto caller_dataset = std::make_shared<ax::ocean::Dataset>();
	{
		std::string file_name = "F:/db/dp/GEBCO_2023.nc";
		ncore::reader::NCoreReaderResult<short> loop_read_result;
		ncore::reader::NCoreReader reader(file_name);
		bool read_exec_result = reader.readArea<short>(area, loop_read_result);
		if (!read_exec_result) {
			return -1;
		}

		auto depth_db = std::make_shared<darr::DimsArray<short>>(loop_read_result["elevation"]);
		caller_dataset->setDepthDB(depth_db);
	}
	{
		std::string file_name = "F:/db/sp/sp_2023_01_00_00.nc";
		ncore::reader::NCoreReaderResult<float> loop_read_result;
		ncore::reader::NCoreReader reader(file_name);
		bool read_exec_result = reader.readArea<float>(area, loop_read_result);
		if (!read_exec_result) {
			return -1;
		}

		auto ssp_db = std::make_shared<darr::DimsArray<float>>(loop_read_result["ssp"]);
		caller_dataset->setSspDB(ssp_db);
	}

	auto caller_source = std::make_shared<ax::core::Source>();
	caller_source->setLongitude(0);
	caller_source->setLatitude(0);
	caller_source->setAltitude(50);
	caller_source->setFrequency(10000);

	if (1) 
	{
		ax::bhp::BhpCaller caller;

		auto caller_param = std::make_shared<ax::param::Line>();
		caller_param->setTargetLongitude(10);
		caller_param->setTargetLatitude(10);
		caller.setParam(caller_param);

		caller.setOceanData(caller_dataset);
		caller.setSource(caller_source);
		auto line_res = caller.Call();
		if (!line_res) {
			std::cout << caller.getLastErrorMessage() << std::endl;
		}
	}

	if (0) 
	{
		auto caller_point_param = std::make_shared<ax::param::Point>();
		caller_point_param->setTargetRangeDistanceKm(314);
		caller_point_param->setTargetDepthNumber(1000);
		// caller_point_param->setTargetRangeNumber(2000);
		// caller_point_param->setTargetBearingCount(16);
		caller_point_param->setTargetRangeCoordNumber(100);
		caller_point_param->setOptIsUseMutiThreads(false);
		ax::bhp::Solver bhp_solver;
		bhp_solver.setOceanDataset(caller_dataset);
		bhp_solver.setSource(caller_source);
		auto point_res = bhp_solver.solvePoint(caller_point_param);
	}

	return 0;
}